const webp = require('webp-converter')
const fs = require('fs')
const path = require('path')
const staticPath = path.join(__dirname, './static')
const distPath = path.join(__dirname, './dist')

const webpToJpg = (imgPath) => {
  const imgName = imgPath.substring(0, imgPath.length - 5)
  webp
    .cwebp(
      path.join(staticPath, imgPath),
      path.join(distPath, `${imgName}.jpg`),
      '-q 100'
    )
    .then((res) => {
      console.log(res)
    })
}

const staticList = fs.readdirSync(staticPath)
staticList.forEach((img) => {
  if (path.extname(img) === '.webp') {
    webpToJpg(img)
  }
})

// webp.cwebp('./1.webp', './1.jpg', '-q 100').then((res) => {
//   console.log(res)
// })
